<!--这是考试详情-->
<template>
	<div class="app-container">
    <div class="clearfix">
			<div class="fl">
			  <el-input @keyup.enter.native="searchPaper" v-model="listQuery.paperName" placeholder="请输入试卷名称"></el-input>
			</div>
			<div class="fl">
				<el-select v-model="listQuery.selectMemberType" placeholder="会员类型"  clearable style="width: 120px">
			    	<el-option value="1" key="1" label="普通用户"></el-option>
			    	<el-option value="2" key="2" label="VIP会员"></el-option>
			    	<el-option value="4" key="4" label="SVIP会员"></el-option>
			    	<el-option value="3" key="3" label="代理商"></el-option>
			    	<el-option value="5" key="5" label="合伙人"></el-option>
			    	<el-option value="6" key="6" label="分公司"></el-option>
				</el-select>
				<el-date-picker :editable="false" type="date" @change="timeCheck(1)" format="yyyy-MM-dd" placeholder="测试日期（开始）" v-model="listQuery.test_time">
                </el-date-picker>
        <el-date-picker :editable="false" type="date" @change="timeCheck(2)" format="yyyy-MM-dd" placeholder="测试日期（结束）"  v-model="listQuery.end_time">
        </el-date-picker>
				<el-button class='search' type="primary" icon="el-icon-search" @click="searchPaper">搜索</el-button>
			</div>
		</div>
			<el-table :data="tableData" :header-row-style="{'font-family': 'PingFangSC-Semibold','backgroundColor': '#f5f7fa','color':'#5c6065'}" row-key="id" v-loading="listLoading" fit highlight-current-row class="margin-t c-width100 color-222 family-PingFangSC-Regular font-s12">
			 	<el-table-column align="center" label="会员名">
			        <template slot-scope="scope">
			          <span>{{scope.row.nickname}}</span>
			        </template>
		      	</el-table-column>
		      	<el-table-column width="100" align="center" label="会员等级">
			        <template slot-scope="scope">
			          <span v-if="scope.row.vipType == 1">普通用户</span>
                <span v-if="scope.row.vipType == 2" style="color:red">VIP</span>
                <span v-if="scope.row.vipType == 3">代理商</span>
                <span v-if="scope.row.vipType == 4" style="color:red">SVIP</span>
                <span v-if="scope.row.vipType == 5">合伙人</span>
                <span v-if="scope.row.vipType == 6">分公司</span>
			        </template>
			    </el-table-column>
		      	<el-table-column align="center" label="测试时间">
			        <template slot-scope="scope">
			          <span>{{scope.row.createTime}}</span>
			        </template>
			    </el-table-column>
			    <el-table-column align="center" label="试卷">
			        <template slot-scope="scope">
			          <span>{{scope.row.paperName}}</span>
			        </template>
			    </el-table-column>
			    <el-table-column width="80" align="center" label="分数">
			        <template slot-scope="scope">
			          <span>{{scope.row.totalpoins}}</span>
			        </template>
			    </el-table-column>
			    <el-table-column width="80" align="center" label="正确率">
			        <template slot-scope="scope">
			          <span>{{scope.row.accuracy * 100}}%</span>
			        </template>
			    </el-table-column>
			    <el-table-column width="120" align="center" label="是否交卷">
			        <template slot-scope="scope">
			       <span v-if="scope.row.status == 1 ">是</span>
            <span v-else>否</span>
			        </template>
			    </el-table-column>
			     <el-table-column  align="center" width="160" label="操作">
			        <template slot-scope="scope">
			        	<b v-if="permission == 3" @click="openDelete(scope.row.examMainId)">删除</b>
                <span v-if="permission == 3" v-show="scope.row.status" class="color-409">|</span>

			        	<b el-button type="primary" v-show="scope.row.status" @click="toPreview(scope.row.examMainId)">预览</b>

	            </template>
			    </el-table-column>
		   </el-table>
		   <div class="block text-c">
				<!--分页组件 current-page:当前页   -->
				<!--   page-sizes:每页几条数据（选项）   -->
				<!--   page-size:每页几条数据   -->
				<!--   total:总条数   -->
			    <el-pagination
			      @size-change="handleSizeChange"
			      @current-change="handleCurrentChange"
			      :current-page="listQuery.currentPage"
			      :page-sizes="[10, 20, 30, 40]"
			      :page-size="10"
			      layout="total, sizes, prev, pager, next, jumper"
			      :total="listQuery.total">
			    </el-pagination>
		</div>
    <previewTest v-show="isPreview" @hidePreview="hidePreview" :examMainId="this.examMainId"></previewTest>
	</div>
</template>

<script>
import previewTest from './components/previewTest.vue'
import { getUserExamInfo, delExamInfo } from '@/api/paper'
import { knowledge_test } from '@/utils/permission'
export default {
  components: {
    previewTest
  },
  created() {
    this.getExamInfo() // 获取考试情况
  },
  data() {
    return {
      permission: 3,
      listQuery: {
        currentPage: 1, // 当前页
        total: null, // 数据总条数
        selectPaperId: null, // 搜索选择的试卷
        selectMemberType: null, // 搜索的会员类型
        paperName: null, // 试卷名称
        test_time: null, // 测试时间(开始)
        end_time: null, // 测试时间(结束)
        limit: null,
        page: 1
      },
      isPreview: false,
      paperData: [], // 试卷列表
      tableData: [], // 考试数据
      listloading: false,
      examMainId: null
    }
  },
  methods: {
    getModelPermission() {
      this.permission = knowledge_test()
    },
    getExamInfo() {
      this.listLoading = true
      // 根据ID查找该专题下得试卷
      getUserExamInfo(this.listQuery).then(res => {
        // 正确回调
        console.log('考试情况----------------' + res)
        this.tableData = res.data.data.data
        this.listQuery.total = res.data.data.total
        console.log('sdsd' + res.data.data.total)
        this.listLoading = false
      })
        .catch(err => {
          console.log(err)
        })
    },
    hidePreview(msg) {
      this.isPreview = msg
    },
    openDelete(id) {
      this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delExamInfo(id).then(res => {
        // 正确回调
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getExamInfo()
        })
          .catch(err => {
            console.log(err)
          })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    linkToDetail(id) {
      location.href = '#/column/columnDetail/' + id
    },
    linkToGive() {
      location.href = '#/column/give'
    },
    linkToGiveList() {
      location.href = '#/column/giveList'
    },
    handleSizeChange(val) { // 切换每页几条数据方法
      this.listQuery.limit = val
      this.getExamInfo()
    },
    handleCurrentChange(val) { // 切换当前页
      this.listQuery.page = val
      this.getExamInfo()
    },
    paperOptionSelect(selectedOption, id) {
      this.listQuery.selectPaperId = selectedOption.paperMainId
    },
    searchPaper() {
      this.getExamInfo()
    },
    toPreview(examMainId) {
      if (examMainId) {
        this.examMainId = examMainId
      } else {
        this.examMainId = 1
      }
      this.isPreview = true
    },
    timeCheck(type) {
      if (this.listQuery.test_time && this.listQuery.end_time && this.listQuery.test_time > this.listQuery.end_time) {
        this.$message({
          message: '结束时间不能小于开始时间',
          type: 'error'
        })

        if (type == 1) {
          this.listQuery.test_time = null
        } else {
          this.listQuery.end_time = null
        }
      }
    }
  },
  mounted() {
    this.getModelPermission()
    this.total = this.tableData.length
  }
}
</script>
<style scoped>
	.block{
		padding: 20px 0;
	}
	.text-c{
		text-align: center;
	}

</style>
